//
//  TAMTNavigationController.swift
//  TAMeetApp
//
//  Created by Admin on 2024/12/3.
//

import UIKit

class TAMTNavigationController: UINavigationController, UIGestureRecognizerDelegate, UINavigationControllerDelegate {
    
    weak var PopDelegate: AnyObject?

    override func viewDidLoad() {
        super.viewDidLoad()

        self.PopDelegate = self.interactivePopGestureRecognizer?.delegate;
        self.delegate = self;
    }
    
    @objc func onBackAction() {
        self.popViewController(animated: true)
    }
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if (self.viewControllers.count > 0) {
            viewController.hidesBottomBarWhenPushed = true
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem.init(image: UIImage(named: "back")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(onBackAction))
        }
        super.pushViewController(viewController, animated: animated)
    }
    
    func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        if(gestureRecognizer == self.interactivePopGestureRecognizer){
            return self.viewControllers.count>1;
        }
        return false
    }

}
